<?php
namespace Admin\Controller;
use Think\Controller;
class VideoController extends Controller {
    public function videoList(){
    	$videosModel=M('videos');//构建一个操作masters表的模型实例
        $videos=$videosModel->order('v_id ')->select();
        $this->videolist=$videos;
         //dump ($videos);
        $this->display();
       
       
    }
     public function delvideo($v_id){
    $videosModel=M('videos'); 
    if (false!==$videosModel->where("v_id=$v_id"/*必须是双引号*/)->delete()) {
            $this->success('删除成功！');
        } else {
            $this->error('删除失败');
        }
}
public function addvideo(){

       $this->display();
    }

public function add(){
	
       if($_FILES['file']['error']==0 ){
            $info=$this->upload();
            $name=$info["file"]["savename"];
        }
        else{
            $name="default.mp4";
        }
        $video = D('videos');
		// $v_date = date('Y-m-d H:i:s',time());

        if($video->create()){
            $video->v_date =  date("Y-m-d H:i:s");
            $video->v_address=$name; 
            if(false!==$video->add())
                      {
                $this->success('发布成功!','videolist');
            }
            else{$this->error('发布失败');}
        }else{
            $this->error($video->getError());
        }
    }
   public function at()
    {
        $localtime = date('Y-m-d H:i:s', time());
        return $localtime;
    }
  public function upload(){
        $upload = new \Think\Upload();// 实例化上传类
        $upload->maxSize   =     314572800000000 ;// 设置附件上传大小
        $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg','mp4','wmv');// 设置附件上传类型
        $upload->rootPath  =     './Public/Video/'; // 设置附件上传根目录  //  
        $upload->autoSub = false;//关闭子目录，默认true
        //$upload->savePath  =     ''; // 设置附件上传(子)目录，默认目录名为年月日
        $info   =   $upload->upload();  // 上传文件 
        if(!$info) {
            $this->error($upload->getError());    
        }
        else{
            return $info;
        }                    
    }
}